package com.itheima.work.day8;

import java.util.Comparator;
import java.util.TreeSet;
/*
.创建一个员工类Employee，有姓名name、年龄age、工资salary属性
	2.创建3个员工对象，添加到TreeSet集合中
	3.要求按照员工的工资排序；如果工资相同，按照年龄排序；如果年龄也相同，再按照姓名的字典顺序排序

* */
public class Test5 {
    public static void main(String[] args) {
//        2.创建3个员工对象，添加到TreeSet集合中
        Employee employee1 = new Employee("张三",25,9000);
        Employee employee2 = new Employee("李斯",28,6000);
        Employee employee3 = new Employee("王武",28,9000);

        TreeSet<Employee> set = new TreeSet<>(new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                int result = o1.getSalary() - o2.getSalary();
                result = result == 0 ? o1.getAge() - o2.getAge() : result;

                result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;

                return result;
            }
        });

        set.add(employee1);
        set.add(employee2);
        set.add(employee3);

        for (Employee employee : set) {
            System.out.println(employee);
        }


    }
}

//        3.要求按照员工的工资排序；如果工资相同，按照年龄排序；如果年龄也相同，再按照姓名的字典顺序排序；
//.创建一个员工类Employee，有姓名name、年龄age、工资salary属性
class Employee{

    private String name;
    private int age;
    private int salary;

    public Employee() {
    }

    public Employee(String name, int age, int salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }
}
